<?php
$isReloadable = true;
require_once("../../../pers/inc.config.php");
require_once('../../_inc/inc.session.php');
require_once('../../_inc/funct.html.php');

$aWhere = array();
if (reqVar('pagifilt')!='') {
	$aWhere[] = " (u.cognome LIKE '%".addslashes(reqVar('pagifilt'))."%' "
		." OR u.nome LIKE '%".addslashes(reqVar('pagifilt'))."%' "
		." OR u.cod_utente LIKE '%".addslashes(reqVar('pagifilt'))."%') ";
}
$sWhere = (count($aWhere)==0)? "":" WHERE ".implode(" AND ",$aWhere);
$sql_sel = "SELECT count(*) AS num_rec " .
		" FROM rgl_utenti u " .$sWhere;
//dbg_($sql_sel);
$objDB->query($sql_sel,'selRec');
$acRec = $objDB->fetch('selRec');
$numRec = $acRec['num_rec'];
$link = $_SERVER['PHP_SELF']."?".$sXSNQS;
$startOffset = 0;
$endOffset = 0;
$sFiltro = rglGetFiltro($link);
$sPaginaz = rglGetPaginaz($link, $numRec, $startOffset, $endOffset);

$sql_sel = "SELECT u.*" .
		" FROM rgl_utenti u " .
		" ORDER BY u.cod_utente ".
		" LIMIT ".$startOffset.",".($endOffset-$startOffset);
$objDB->query($sql_sel,'selRec');
$cmdL = "";
$cmdR = "&nbsp;&nbsp;&nbsp;";
if (true) {
	$cmdR .= "<a class=\"cmd1\" href=\"utentiIns.php?$sXSNQS\">nuovo utente</a>";
}
$cmdR .= cmdTorna(); 

testaHtml('Gestione applicazione', $msgPag, 'gest');
echo getHtmlForm();
echo getHtmlHidden('xsn',XSN);
echo getHtmlHidden('startoffset');
?>
<table class="cmd1" border="0" cellpadding="3" cellspacing="1" width="100%" align='center'>
   <tr>
      <td class="cmd1" align="left">
         <?=$cmdL?>
      </td>
      <td class="cmd1" align="right">
         <?=$cmdR?>
      </td>
   </tr>
   <tr>
      <td class="cmd1" align="left">
			<?=$sFiltro?>
      </td>
      <td class="cmd1" align="right">
			<?=$sPaginaz?>
      </td>
   </tr>
</table>
<table class="tab1" border="0" cellpadding="3" cellspacing="1" width="100%" align='center'>
   <tr>
      <td class="tit1" width='10%' align='center' colspan='5'>Lista utenti</td>
   </tr>
   <tr>
      <td class="lab1" width='10%' align='center'>Codice</td>
      <td class="lab1" width='30%' align='center'>Cognome e Nome</td>
      <td class="lab1" width='10%' align='center'>E_mail</td>
      <td class="lab1" width='10%' align='center'>Cellulare</td>
      <td class="lab1" width='40%' align='center'>Ruoli</td>
   </tr>
<? 
$clRF = 'txt2';
while($acX = $objDB->fetch('selRec')) { 
	$clRF = ($clRF=='txt1')?'txt2':'txt1';	
?>
   <tr>
      <td class="<?=$clRF?>">
      	<a href='utentiView.php?id=<?=$acX['id_utente']."&$sXSNQS"?>' class="<?=$clRF?>"
      	 	style='font-family:lucida console,courier;'>
            <?
            echo $acX['cod_utente'];
            ?>
         </a>
      </td>
      <td class="<?=$clRF?>" align='left'><? echo $acX['cognome']." ".$acX['nome']; ?></td>
      <td class="<?=$clRF?>" align='left'><? echo $acX['e_mail']; ?></td>
      <td class="<?=$clRF?>" align='left'><? echo $acX['cellulare']; ?></td>
      <td class="<?=$clRF?>">
            <?
	$sql_sel = "SELECT r.cod_ruolo" .
			" FROM rgl_utenti_ruoli ur " .
			" INNER JOIN rgl_ruoli r ON r.id_ruolo = ur.id_ruolo".
			" WHERE ur.id_utente = ".$acX['id_utente'].
			" ORDER BY r.cod_ruolo ";
	$objDB->query($sql_sel,'selRuo');
	$virg = '';
	while($acY = $objDB->fetch('selRuo')) {
	            echo $virg.$acY['cod_ruolo'];
	            $virg = ', ';
	}
            ?>
      </td>
   </tr><? 
}?>
</table>
<table class="cmd1" border="0" cellpadding="3" cellspacing="1" width="100%" align='center'>
   <tr>
      <td class="cmd1" align="right">
<?=$sPaginaz?>
      </td>
   </tr>
</table>
<?
echo "</form>\n";
codaHtml();
exit();
?>
